//
//  DEWRingBtnTableViewCell.m
//  OtherDemo
//
//  Created by kangbinbin on 2018/7/24.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWRingBtnTableViewCell.h"
#import "ButtonCollectionCell.h"
#import "UIImageView+WebCache.h"

@interface DEWRingBtnTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
/** <#type#> */
@property (strong, nonatomic) UICollectionViewFlowLayout *layout;
/** <#type#> */
@property (strong, nonatomic) UICollectionView  *collectView;

@end


@implementation DEWRingBtnTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        [self creatView];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self creatView];

}


-(void)creatView{
    
    _layout = [[UICollectionViewFlowLayout alloc]init];
    _layout.scrollDirection = UICollectionViewScrollDirectionVertical;///滑动方向
    _layout.itemSize = CGSizeMake(DEWScreenWidth/4, 100);
    _layout.minimumLineSpacing = 0;///行距
    _layout.minimumInteritemSpacing = 0;///间距
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);///cell呈现区域边界边距
    
    _collectView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, DEWScreenWidth , 100 * 2) collectionViewLayout:_layout];
    _collectView.scrollEnabled = NO;
    _collectView.backgroundColor = [UIColor whiteColor];
    
    _collectView.delegate = self;
    _collectView.dataSource = self;
    [self addSubview:_collectView];
    
    ///注册
    [self.collectView registerClass:[ButtonCollectionCell class] forCellWithReuseIdentifier:@"collectionID"];

    
}



-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ButtonCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionID" forIndexPath:indexPath];
    
    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 8, 50, 50)];
    imgView.image = [UIImage imageNamed:@"我的老乡"];
    [cell addSubview:imgView];
    
    UILabel *subL = [[UILabel alloc]init];
    subL.frame = CGRectMake(0, imgView.bottom + 8,  (DEWScreenWidth - 1) /4, 17);
//    subL.text = [NSString stringWithFormat:@"%@",self.itemArray[indexPath.row][@"categoryName"]];
    subL.text = @"测试数据";
    subL.textColor = UIColorFromRGB(333333);
    subL.font = [UIFont systemFontOfSize:12];
    subL.textAlignment = NSTextAlignmentCenter;
    [cell addSubview:subL];
    
    return cell;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//
//    tagg = indexPath.row;
//
//    [self.collectView reloadData];
//
//
//
//    if (_delegate && [_delegate respondsToSelector:@selector(didSelectAtZBItem:)]) {
//
//
//        [_delegate didSelectAtZBItem:indexPath.row];
//
//
//    }
//
    
    
    
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
